using System;
using System.Windows.Controls;
using System.Windows.Data;
using System.Xml;
using System.Xml.Linq;
using System.Linq;

namespace WizardSample
{
    public partial class WizardPageAuthSummary : WizardPageBase
    {
        public WizardPageAuthSummary()
        {
            InitializeComponent();
        }

        public override void BindToData(Object contextData)
        {
            AuthenticationWizardData wizardData = contextData as AuthenticationWizardData;

            // Bind wizard data
            if (wizardData != null)
            {
                XDocument xDocument = new XDocument();

                xDocument.Add(
                    new XElement(@"Info",
                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"Authentication Service VirtualPath"),
                                              new XAttribute(@"Value", wizardData.AuthServiceVirtualPath)
                                     ),
                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"Authentication Service IIS Site"),
                                              new XAttribute(@"Value",
                                                             wizardData.IISSiteList[wizardData.IISSiteItem]
                                                                 .IISSite)
                                     ),
                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"Farm"),
                                              new XAttribute(@"Value", wizardData.FarmName)
                                     ),

                                 from x in wizardData.FarmServers
                                 select new XElement(@"Item",
                                                     new XAttribute(@"Category", @"Farm Servers"),
                                                     new XAttribute(@"Value", x)
                                     ),

                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"XML Service port"),
                                              new XAttribute(@"Value", wizardData.FarmPort)
                                     ),
                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"XML Service transport type"),
                                              new XAttribute(@"Value", wizardData.FarmTransport)
                                     ),
                                 new XElement(@"Item",
                                              new XAttribute(@"Category", @"SSL Relay port"),
                                              new XAttribute(@"Value", wizardData.FarmSSLRelayPort)
                                     )
                        ));

                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xDocument.ToString());

                XmlDataProvider xmlProvider = new XmlDataProvider();
                xmlProvider.Document = xmlDocument;
                xmlProvider.XPath = @"/Info/Item";

                CollectionViewSource viewSource = new CollectionViewSource()
                                                      {
                                                          Source = xmlProvider,
                                                      };
                viewSource.GroupDescriptions.Add(
                    new PropertyGroupDescription()
                        {
                            PropertyName = "@Category"
                        });

                this.summaryListView.DataContext = viewSource;
            }
        }
    }
}
